//
//  MYGMincrostationToolView.swift
//  MYDoctor
//
//  Created by 小火科技 on 2024/5/23.
//

import UIKit

class MYGMincrostationToolView: UIView {
    var clickMenumBlock:((_ isMine:Bool)->Void)?
    var clickMineButtonBlock:((_ index:Int)->Void)? //关于我 0 全部 1我的介绍 2专业擅长 3临床实验
    var clickDyButtonBlock:((_ index:Int)->Void)? //我的动态 0全部 1图片 2视频 3个人报道
    
    @objc private func introduceAction(){
        UIView.animate(withDuration: 0.5) { [self] in
            scrollLineView.jf_centerX = introduceBtn.jf_centerX
            introduceBtn.isSelected = true
            zhuanyeBtn.isSelected = false
            testBtn.isSelected = false
        }
        
        self.clickMineButtonBlock?(0)
        
    }
    @objc private func zhuanyeAction(){
        UIView.animate(withDuration: 0.5) { [self] in
            scrollLineView.jf_centerX = zhuanyeBtn.jf_centerX
            introduceBtn.isSelected = true
            zhuanyeBtn.isSelected = false
            testBtn.isSelected = false
        }
        self.clickMineButtonBlock?(2)
    }
    @objc private func testAction(){
        UIView.animate(withDuration: 0.5) { [self] in
            scrollLineView.jf_centerX = testBtn.jf_centerX
            introduceBtn.isSelected = true
            zhuanyeBtn.isSelected = false
            testBtn.isSelected = false
        }
        self.clickMineButtonBlock?(3)
    }
    
    //0全部 1图片 2视频 3个人报道
    // 全部
    @objc private func introduceAction1(){
        UIView.animate(withDuration: 0.5) { [self] in
            scrollLineView.jf_centerX = introduceBtn1.jf_centerX
            introduceBtn1.isSelected = true
            zhuanyeBtn1.isSelected = false
            testBtn1.isSelected = false
            videoBtn.isSelected = false
        }
        self.clickDyButtonBlock?(0)
    }
    // 图片
    @objc private func zhuanyeAction1(){
        UIView.animate(withDuration: 0.5) { [self] in
            scrollLineView.jf_centerX = zhuanyeBtn1.jf_centerX
        }
        introduceBtn1.isSelected = false
        zhuanyeBtn1.isSelected = true
        testBtn1.isSelected = false
        videoBtn.isSelected = false
        self.clickDyButtonBlock?(1)
    }
    //视频
    @objc private func testAction1(){
        UIView.animate(withDuration: 0.5) { [self] in
            scrollLineView.jf_centerX = testBtn1.jf_centerX
        }
        introduceBtn1.isSelected = false
        zhuanyeBtn1.isSelected = false
        testBtn1.isSelected = true
        videoBtn.isSelected = false
        self.clickDyButtonBlock?(2)
    }
    //报道
    @objc private func videotAction(){
        UIView.animate(withDuration: 0.5) { [self] in
            scrollLineView.jf_centerX = videoBtn.jf_centerX
        }
        introduceBtn1.isSelected = false
        zhuanyeBtn1.isSelected = false
        testBtn1.isSelected = false
        videoBtn.isSelected = true
        self.clickDyButtonBlock?(3)
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        configUI()
        changeButton(true)
    }
    
    //更新
    func changeButton(_ isMine: Bool){
        UIView.animate(withDuration: 0.5) { [self] in
            scrollLineView.jf_centerX = introduceBtn.jf_centerX
        }
        if isMine {
            introduceBtn.isHidden = false
            zhuanyeBtn.isHidden = false
            testBtn.isHidden = false
            
            introduceBtn1.isHidden = true
            zhuanyeBtn1.isHidden = true
            testBtn1.isHidden = true
            videoBtn.isHidden = true
            
            scrollLineView.snp.updateConstraints { make in
                make.size.equalTo(CGSize(width: screenWidth/3, height: 1))
            }
            
            self.clickMenumBlock?(true)
        }else {
            introduceBtn.isHidden = true
            zhuanyeBtn.isHidden = true
            testBtn.isHidden = true
            videoBtn.isHidden = true
            
            introduceBtn1.isHidden = false
            zhuanyeBtn1.isHidden = false
            testBtn1.isHidden = false
            videoBtn.isHidden = false
            scrollLineView.snp.updateConstraints { make in
                make.size.equalTo(CGSize(width: screenWidth/4, height: 1))
            }
            self.clickMenumBlock?(false)
        }
        
    }
    
    func configUI(){
        self.backgroundColor = .white
        
        addSubview(introduceBtn)
        introduceBtn.snp.makeConstraints { make in
            make.left.top.equalToSuperview()
            make.size.equalTo(CGSize(width: screenWidth/3, height: SCALEWIDTH(40)))
        }
        addSubview(zhuanyeBtn)
        zhuanyeBtn.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(screenWidth/3)
            make.top.equalTo(introduceBtn)
            make.size.equalTo(CGSize(width: screenWidth/3, height: SCALEWIDTH(40)))
        }
        addSubview(testBtn)
        testBtn.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(screenWidth/3*2)
            make.top.equalTo(introduceBtn)
            make.size.equalTo(CGSize(width: screenWidth/3, height: SCALEWIDTH(40)))
        }
        
        addSubview(introduceBtn1)
        let count:CGFloat = 4
        introduceBtn1.snp.makeConstraints { make in
            make.left.top.equalToSuperview()
            make.size.equalTo(CGSize(width: screenWidth/count, height: SCALEWIDTH(40)))
        }
        addSubview(zhuanyeBtn1)
        zhuanyeBtn1.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(screenWidth/count)
            make.top.equalTo(introduceBtn)
            make.size.equalTo(CGSize(width: screenWidth/count, height: SCALEWIDTH(40)))
        }
        addSubview(testBtn1)
        testBtn1.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(screenWidth/count*2)
            make.top.equalTo(introduceBtn)
            make.size.equalTo(CGSize(width: screenWidth/count, height: SCALEWIDTH(40)))
        }
        addSubview(videoBtn)
        videoBtn.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(screenWidth/count*3)
            make.top.equalTo(introduceBtn)
            make.size.equalTo(CGSize(width: screenWidth/count, height: SCALEWIDTH(40)))
        }
        
        addSubview(scrollLineView)
        scrollLineView.snp.makeConstraints { make in
            make.left.equalToSuperview()
            make.top.equalTo(SCALEWIDTH(49))
            make.size.equalTo(CGSize(width: screenWidth/3, height: 1))
        }
    }
    // 关于我
    lazy var introduceBtn:UIButton = {
        let cont = UIButton()
        cont.setImage(UIImage(named: "dorctorDetail_introduce"), for: .normal)
        cont.setImage(UIImage(named: "dorctorDetail_introduce"), for: .selected)
        cont.addTarget(self, action: #selector(introduceAction), for: .touchUpInside)
        return cont
    }()
    lazy var zhuanyeBtn:UIButton = {
        let cont = UIButton()
        cont.setImage(UIImage(named: "dorctorDetail_zhuanye"), for: .normal)
        cont.addTarget(self, action: #selector(zhuanyeAction), for: .touchUpInside)
        return cont
    }()
    lazy var testBtn:UIButton = {
        let cont = UIButton()
        cont.setImage(UIImage(named: "dorctorDetail_test_normal"), for: .normal)
        cont.setImage(UIImage(named: "dorctorDetail_test"), for: .selected)

        cont.addTarget(self, action: #selector(testAction), for: .touchUpInside)
        return cont
    }()
    
    //我的动态
    lazy var introduceBtn1:UIButton = {
        let cont = UIButton()
        cont.setImage(UIImage(named: "fang"), for: .normal)
        cont.setImage(UIImage(named: "fang"), for: .selected)
        cont.addTarget(self, action: #selector(introduceAction1), for: .touchUpInside)
        return cont
    }()
    lazy var zhuanyeBtn1:UIButton = {
        let cont = UIButton()
        cont.setImage(UIImage(named: "photo_normal"), for: .normal)
        cont.setImage(UIImage(named: "photo"), for: .selected)
        cont.addTarget(self, action: #selector(zhuanyeAction1), for: .touchUpInside)
        return cont
    }()
    //视频
    lazy var testBtn1:UIButton = {
        let cont = UIButton()
        cont.setImage(UIImage(named: "video_normal"), for: .normal)
        cont.setImage(UIImage(named: "video"), for: .selected)
        cont.addTarget(self, action: #selector(testAction1), for: .touchUpInside)
        return cont
    }()
    //报道
    lazy var videoBtn:UIButton = {
        let cont = UIButton()
        cont.setImage(UIImage(named: "video2_normal"), for: .normal)
        cont.setImage(UIImage(named: "video2"), for: .selected)
        cont.addTarget(self, action: #selector(videotAction), for: .touchUpInside)
        return cont
    }()
    
    
    lazy var scrollLineView:UIView = {
        let cont = UIView()
        cont.backgroundColor = .rgba(255, 2, 0, 1)
        return cont
    }()

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}


